﻿using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Globalization;
using System.Transactions;

//自定义命名空间
using DreamCube.Foundation.Basic.Cache;
using DreamCube.Foundation.Basic.Enums;
using DreamCube.Foundation.Basic.Objects.EqualityComparers;

namespace DreamCube.Framework.DataAccess.Basic
{
    /// <summary>
    /// 数据库基础对象
    /// </summary>
    public abstract partial class Database
    {
        #region "字段"

        /// <summary>
        /// 查询空表、为了获取表定义的sql语句模板
        /// 默认为：select * from {0} where 1=0
        /// </summary>
        protected virtual String SelectEmptyDatableSqlTemplate
        { 
            get { return "select * from {0} where 1=0"; } 
        }

        /// <summary>
        /// 连接字符串
        /// </summary>
        protected String connectionStringStr;
        /// <summary>
        /// 连接字符串对象
        /// </summary>
        private ConnectionString connectionStringObject =null;
        readonly DbProviderFactory dbProviderFactory;

        /// <summary>
        /// 表定义缓冲区
        /// </summary>
        private DictionaryCachePool<String, DataTable> dataTableCachePool =
            new DictionaryCachePool<String, DataTable>(new StringEqualityIgnoreCaseComparerGeneric());

        #endregion

        #region "属性"

        public ConnectionString ConnectionString
        {
            get
            {
                if (connectionStringObject == null)
                {
                    connectionStringObject = new ConnectionString(connectionStringStr,
                                                                  Properties.Resources.UserNameToken,
                                                                  Properties.Resources.PasswordToken,
                                                                  Properties.Resources.DataSourceToken);
                }
                return connectionStringObject;
            }
        }

        /// <summary>
        /// 数据库提供程序
        /// </summary>
        public DbProviderFactory DbProviderFactory
        {
            get { return dbProviderFactory; }
        }

        /// <summary>
        /// 是否支持发现参数；根据存储过程名，获得存储过程的参数
        /// </summary>
        public virtual Boolean SupportsParemeterDiscovery
        {
            get { return false; }
        }

        #endregion
    }
}
